<?php
namespace Admin\Controller;
use Think\Controller;

/**
* 广告---首页轮播图
*/
class AdController extends BaseController
{
	public function ad()
	{
		$id = $_GET['id'];
		if(!empty($id))
		{
			$info = M('ad')->where('id = '.$id)->find();
			$this->assign('info', $info);
		}
		$act = empty($id) ? 'add' : 'edit';
		$this->assign('act', $act);
		$this->display();
	}

	public function adList()
	{
		$this->display();
	}

	public function adHandle()
	{
		$data = $_POST;
		if($data['act'] == 'add')
		{
			unset($data['id']);
			$data['add_time'] = time();
			$res = M('ad')->add($data);
		}
		else if($data['act'] == 'edit')
		{
			$res = M('ad')->where('id = '.$id)->save($data);
		}
		elseif($data['act'] == 'del' && $data['id'] > 1)
		{
			$res = M('ad')->where('id = '.$id)->delete();
		}

		if($res)
		{
			returnJsonStr(0, '操作成功');
		}
		else
		{
			returnJsonStr(1, '操作失败');
		}

	}
}